package com.ruoyi.sgsc.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.annotation.Anonymous;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.sgsc.domain.categories;
import com.ruoyi.sgsc.service.IcategoriesService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 分类名Controller
 * 
 * @author wy
 * @date 2024-09-29
 */
@Anonymous
@RestController
@RequestMapping("/sgsc/categories")
public class categoriesController extends BaseController
{
    @Autowired
    private IcategoriesService categoriesService;

    /**
     * 查询分类名列表
     */
    @GetMapping("/list")
    public TableDataInfo list(categories categories)
    {
        startPage();
        List<categories> list = categoriesService.selectcategoriesList(categories);
        return getDataTable(list);
    }

    /**
     * 导出分类名列表
     */

    @PostMapping("/export")
    public void export(HttpServletResponse response, categories categories)
    {
        List<categories> list = categoriesService.selectcategoriesList(categories);
        ExcelUtil<categories> util = new ExcelUtil<categories>(categories.class);
        util.exportExcel(response, list, "分类名数据");
    }

    /**
     * 获取分类名详细信息
     */

    @GetMapping(value = "/{categoryId}")
    public AjaxResult getInfo(@PathVariable("categoryId") Long categoryId)
    {
        return success(categoriesService.selectcategoriesByCategoryId(categoryId));
    }

    /**
     * 新增分类名
     */

    @PostMapping
    public AjaxResult add(@RequestBody categories categories)
    {
        return toAjax(categoriesService.insertcategories(categories));
    }

    /**
     * 修改分类名
     */

    @PutMapping
    public AjaxResult edit(@RequestBody categories categories)
    {
        return toAjax(categoriesService.updatecategories(categories));
    }


    /**
     * 删除分类名
     */

	@DeleteMapping("/{categoryIds}")
    public AjaxResult remove(@PathVariable Long[] categoryIds)
    {
        return toAjax(categoriesService.deletecategoriesByCategoryIds(categoryIds));
    }
}
